const express = require('express');

const noteModel = require('../db/model/noteModel');


const verifyLogin = require('../middlewares/verifylogin');

const router = express.Router();



router.get('/addnote',verifyLogin,(req,res)=>{
    res.render('addnote.html')
})

router.get('/',(req,res)=>{
    res.redirect('/list')
})

router.get('/list',(req,res)=>{
    let username = req.session.username || null
    noteModel.find((err,data)=>{
        res.render('list.html',{data,username})
    })
  
})

router.get('/update',verifyLogin,(req,res)=>{
    let id = req.query.id
    noteModel.findById(id,(err,data)=>{
        res.render('update.html',{data})
    })
})

router.get('/detail/:id',(req,res)=>{
    let id = req.params.id
    noteModel.findById(id,(err,data)=>{
        res.render('detail.html',{data})
    })
})

router.get('/center',verifyLogin,(req,res)=>{
    res.render('center.html');
})

module.exports = router